cmake_minimum_required(VERSION 3.0.0)

set(MODULE_NAME "AlsaAudioUtils")
set(${MODULE_NAME}_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/include" CACHE INTERNAL "${MODULE_NAME} of the sources direcotry.")
set(${MODULE_NAME}_LIBRARIES "${MODULE_NAME}" CACHE INTERNAL "${MODULE_NAME} of the library.")

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# find_package 命令还可以用来加载 cmake 的功能模块
find_package(PkgConfig REQUIRED)
# 加载 FindPkgConfig 模块后就可以使用 pkg_check_modules 命令加载需要的库
# 执行 pkg_check_modules 命令加载库也会设置一些类似执行 find_package 加载库后设置的变量：
# Alsa_FOUND
# Alsa_INCLUDE_DIRS
# Alsa_LIBRARIES
pkg_check_modules(Alsa REQUIRED alsa)

add_library(${MODULE_NAME}
    "src/AlsaAudioUtils.c"
)
target_include_directories(${MODULE_NAME} PRIVATE
    ${Alsa_INCLUDE_DIRS}
)
target_link_libraries(${MODULE_NAME}
    ${Alsa_LIBRARIES}
)

# add_subdirectory(lib/AlsaAudioUtils)
# target_include_directories(${MODULE_NAME} PRIVATE
#     ${AlsaAudioUtils_INCLUDE_DIRS}
# )
# target_link_libraries(${MODULE_NAME}
#     ${AlsaAudioUtils_LIBRARIES}
# )

# AlsaAudioUtils Test
option(ENABLE_ALSAAUDIOUTILS_TEST "Enable building AlsaAudioUtils test" ON)
if(ENABLE_ALSAAUDIOUTILS_TEST)
    add_subdirectory(test/native-alsa-base-test)
    add_subdirectory(test/alsa-base-test)
endif(ENABLE_ALSAAUDIOUTILS_TEST)